//
//  UIAlertController+Extension.m
//  QIPeiService
//
//  Created by qihwatech on 16/8/25.
//  Copyright © 2016年 qihwatech. All rights reserved.
//

#import "UIAlertController+Extension.h"

@implementation UIAlertController (Extension)

+ (UIAlertController *)initWithMessage:(NSString *)message bolck:(void (^)(void))block cancelBolck:(void (^)(void))cancelBlock
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *okButton = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
    UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"确认" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        if (action) {
            block();
        }
    }];
    [alertController addAction:cancelButton];
    [alertController addAction:okButton];
    
    //修改title
    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:message];
    [alertControllerStr addAttribute:NSForegroundColorAttributeName value:UIColorWithRGB(102, 102, 102) range:NSMakeRange(0, message.length)];
    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, message.length)];
    [alertController setValue:alertControllerStr forKey:@"attributedTitle"];
    // 修改按钮颜色
    [cancelButton setValue:navBarColor forKey:@"titleTextColor"];
    [okButton setValue:UIColorWithRGB(102, 102, 102) forKey:@"titleTextColor"];
    
    return alertController;
}


@end
